/**
 * Created by zhangqiang on 16/12/18.
 */

const lf = liefeng,
    R = React,
    RC = React.createClass,
    log = lf.utils.log,
    ajax = lf.utils.ajax,
    doAction = lf.bridgeJs.doAction,
    fmt = 'yyyy-MM-dd hh:mm:ss',
    imgPre = '../public/images/finger/',
    formatTime = lf.utils.format;

const waitForSend = 'waitForSend';

const Product = RC({
    getInitialState() {
        return {}
    },
    componentDidMount() {

    },
    render() {
        let data = this.props.data,
            type = '',
            btns = [],
            color = '';

        switch (data.status) {
            case waitForSend:
                type = '待发货';
                btns = ['发货'];
                color = 'pink';
                break;
            case waitForSend:
                type = '待回复';
                btns = ['忽略', '回复'];
                color = 'blue';
                break;
            case waitForComfirm:
                type = '待确认';
                btns = ['取消订单', '确定订单'];
                color = '';
                break;
            case waitForReceipt:
                type = '待收货';
                btns = ['忽略', '收货'];
                color = '';
                break;
            default:
                type = '待处理';
                btns = ['待处理', '处理'];
                color = '';
                break;
        }
        let btnList = btns.map((btn, i)=> {
            return <span className={"btn btn-send " + (btns.length > 1 && i == 0 ? 'grey' : '')}>{btn}</span>
        })
        return <div className="product mui-table-view-cell">
                    <div className="prod-img">
                        <img src={imgPre + data.img} alt=""/>
                    </div>
                    <ul className="describe">
                        <li><span>皇家富士苹果</span> <span>￥8.00</span></li>
                        <li>库存：200</li>
                        <li>发布日期：2015-07-07</li>
                    </ul>
                    <div className="btn-add ">
                        <span className="btn">删除</span>
                        <span className="btn">下架</span>
                    </div>
                </div>
    }
});

const Root = RC({
    getInitialState() {
        return {}
    },
    componentDidMount() {
        let $edit = $(R.findDOMNode(this.refs.edit));
        $edit.on('tap',function(){
            doAction('store-sale-add.html','仓库中')
        })
        
    },
    render() {
        let data = [
                {
                    productBand: '千岛果',
                    productPrice: '23.5',
                    productName: '皇家富士苹果',
                    status: 'waitForSend',//0
                    count: '23.5',
                    sum: '23',
                    img: 'apple.jpg',
                }, {
                    productBand: '千岛果',
                    productPrice: '23.5',
                    productName: '皇家富士苹果',
                    status: 'waitForSend',//0
                    count: '23.5',
                    sum: '23',
                    img: 'apple.jpg',
                }, {
                    productBand: '千岛果',
                    productPrice: '23.5',
                    productName: '皇家富士苹果',
                    status: 'waitForSend',//0
                    count: '23.5',
                    sum: '23',
                    img: 'apple.jpg',
                }, {
                    productBand: '千岛果',
                    productPrice: '23.5',
                    productName: '皇家富士苹果',
                    status: 'waitForSend',//0
                    count: '23.5',
                    sum: '23',
                    img: 'apple.jpg',
                }, {
                    productBand: '千岛果',
                    productPrice: '23.5',
                    productName: '皇家富士苹果',
                    status: 'waitForSend',//0
                    count: '23.5',
                    sum: '23',
                    img: 'apple.jpg',
                },
            ],
            list = data.map((info, i)=> {
                return <Product data={info} key={i}/>
            })

        return <div className="all-order">
                       <ul className="setup mui-table-view-cell">
                           <li>全部下架</li>
                           <li ref="edit">编辑</li>
                       </ul>
                    {list}
                  </div>
           }
});

lf.appJs.getUser(function (user) {
    R.render(<Root user={user}/>, document.getElementById('root'),
        function () {
            $('#root').css({
                'background-color': '#ededed',
                'margin-bottom': '.3rem' //与底部撑开
            });
        }
    );
});